/**  
 * All rights Reserved, Designed By <a href="www.itttq.com" target="_blank">www.itttq.com</a>
 * @date:   2018-01-6 11:42:21
 * @Copyright: 2017 <a href="www.itttq.com" target="_blank">www.itttq.com</a> Inc. All rights reserved. 
 */
package com.itttq.gshop.admin.controller.sys;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.itttq.gshop.admin.controller.GenericController;
import com.itttq.gshop.domain.to.PageParamTo;
import com.itttq.gshop.domain.to.ResultPageTo;
import com.itttq.gshop.domain.po.SysLogModulePo;
import com.itttq.gshop.generic.connector.ISysLogModuleConnector;

@RestController
@RequestMapping("sys/logModule")
public class SysLogModuleController extends GenericController {
	private static final long serialVersionUID = 532162096896923215L;
	@Autowired
	private ISysLogModuleConnector sysLogModuleConnector;
	
	/**
	 * 根据条件查询SysLogModulePo对象，并分页
	 * 
	 * @param sysLogModule
	 * @param request
	 * @return
	 * @Author 迷蝶
	 * @return ModelAndView
	 */
	@RequestMapping("logModules.html")
	public ModelAndView getSysLogModules(SysLogModulePo sysLogModule, HttpServletRequest request) {
		ModelAndView mv = new ModelAndView("/sys/logModules");
		PageParamTo ppt = null == request ? new PageParamTo() : getPageParam(request);
		sysLogModule.setStart(ppt.getStart());
		sysLogModule.setSize(ppt.getSize());
		ResultPageTo<SysLogModulePo> rpt = sysLogModuleConnector.getSysLogModules(sysLogModule);
		this.getPageMv("logModules", mv, rpt);
		mv.addObject("logModule", sysLogModule);
		return mv;
	}

	
	/**
	 * 跳转到新增页面
	 * @return
	 */
	@RequestMapping("add.html")
	public ModelAndView addSysLogModule() {
		ModelAndView mv = new ModelAndView("/sys/logModuleAdd");
		
		return mv;
	}
	/**
	 * 跳转到查看页面
	 * @param id
	 * @return
	 */
	@RequestMapping("view/{id}.html")
	public ModelAndView viewSysLogModule(@PathVariable("id") Integer id) {
		ModelAndView mv = addSysLogModule();
		if(id != null) {
			mv.addObject("logModule", sysLogModuleConnector.getSysLogModule(id));
		}
		mv.addObject("op", "view");
		return mv;
	}
	/**
	 * 跳转到编辑页面
	 * @param id
	 * @return
	 */
	@RequestMapping("edit/{id}.html")
	public ModelAndView editSysLogModule(@PathVariable("id") Integer id) {
		ModelAndView mv = viewSysLogModule(id);
		mv.addObject("op", "edit");
		return mv;
	}
	
	/**
	 * 保存SysLogModulePo对象，无ID则新增，有ID则更新
	 * 
	 * @param sysLogModule
	 * @return
	 * @Author 迷蝶
	 * @return ModelAndView
	 */
	@RequestMapping("save.html")
	public ModelAndView saveSysLogModule(SysLogModulePo sysLogModule) {
		sysLogModuleConnector.saveSysLogModule(sysLogModule);
		return getSysLogModules(new SysLogModulePo(), null);
	}

	/**
	 * 根据ID删除SysLogModulePo对象
	 * 
	 * @param id
	 * @return
	 * @Author 迷蝶
	 * @return ModelAndView
	 */
	@RequestMapping("del/{id}.html")
	@ResponseBody
	public ModelAndView delSysLogModule(@PathVariable("id") Integer id) {
		if(id != null) {
			sysLogModuleConnector.delSysLogModule(id);
		}
		return getSysLogModules(new SysLogModulePo(), null);
	}
}